/*
 * Copyright (c) 2007 by Chances.
 * $CVSHeader: IPTV_VAS_Release1/src/commons/chances/vas/commons/utils/CodeUtils.java,v 1.1 2008/04/17 02:23:14 chenxx Exp $
 * $Author: chenxx $
 * $Date: 2008/04/17 02:23:14 $
 * $Revision: 1.1 $
 */
package mxmf.utils;

import org.apache.commons.lang3.RandomStringUtils;

import mxmf.entity.CmsEntity;
public class CodeUtils {

    private static final int DEFAULT_NUM_LEN = 8;

    /**
     * 生成以类名开头的编码.
     * 
     * @param clazz
     *            类
     * @return
     */
    public static String generate(CmsEntity entity) {
        return generate(entity, entity.getId());
    }

    public static String generate(Object entity, Long entityId) {
        StringBuffer code = new StringBuffer(entity.getClass().getSimpleName().toLowerCase());
        code.append("_");
        code.append(RandomStringUtils.randomNumeric(DEFAULT_NUM_LEN));
        code.append(entityId);
        return code.toString();
    }

    private CodeUtils() {

    }


}
